package com.bootdo.act.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.act.domain.ActDetailsDO;
import com.bootdo.act.domain.ActSignUpDO;
import com.bootdo.act.service.ActDetailsService;
import com.bootdo.act.service.ActSignUpService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 报名表
 * 
 * @author kwx
 * @email 904358838@qq.com
 * @date 2017-12-27 15:51:56
 */
 
@Controller
@RequestMapping("/act/actSignUp")
public class ActSignUpController {
	@Autowired
	private ActSignUpService actSignUpService;
	
	@Autowired
	private ActDetailsService actDetailsService;
	
	/**
	 * 报名管理页面
	 * @return
	 */
	@GetMapping()
	@RequiresPermissions("act:actSignUp:actSignUp")
	String ActSignUp(){
	    return "act/actSignUp/actSignUp";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("act:actSignUp:actSignUp")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ActSignUpDO> actSignUpList = actSignUpService.list(query);
		int total = actSignUpService.count(query);
		PageUtils pageUtils = new PageUtils(actSignUpList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("act:actSignUp:add")
	String add(){
	    return "act/actSignUp/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("act:actSignUp:edit")
	String edit(@PathVariable("id") Long id,Model model){
		ActSignUpDO actSignUp = actSignUpService.get(id);
		model.addAttribute("actSignUp", actSignUp);
	    return "act/actSignUp/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("act:actSignUp:add")
	public R save( ActSignUpDO actSignUp){
		if(actSignUpService.save(actSignUp)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("act:actSignUp:edit")
	public R update( ActSignUpDO actSignUp){
		actSignUpService.update(actSignUp);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("act:actSignUp:remove")
	public R remove( Long id){
		if(actSignUpService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("act:actSignUp:batchRemove")
	public R remove(@RequestParam("ids[]") Long[] ids){
		actSignUpService.batchRemove(ids);
		return R.ok();
	}
	
	/**
	 * 活动列表页面
	 * @return
	 */
	@GetMapping("/listDetails")
	@RequiresPermissions("act:actSignUp:actSignUp")
	String listDetails(){
	    return "act/actSignUp/listDetails";
	}
	
	/**
	 * 获取可以报名的活动
	 * @param params
	 * @return
	 */
	@ResponseBody
	@GetMapping("/getDetails")
	public PageUtils getDetails(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ActDetailsDO> actDetailsList = actDetailsService.list(query);
		int total = actDetailsService.count(query);
		PageUtils pageUtils = new PageUtils(actDetailsList, total);
		return pageUtils;
	}
	
}
